package com.elinshaw.hive;

import java.sql.*;

public class HiveApplication {

    private static String driverName = "org.apache.hive.jdbc.HiveDriver";
    //private static String connctUrl = "jdbc:hive2://192.168.100.73:10000/db_hive_test";
    private static String connctUrl = "jdbc:hive2://192.168.100.73:10000/db_hive_test;AuthMech=3;UID=root;PWD=thrift";
    private static String userName = "root";
    private static String password = "thrift";

    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        Class.forName(driverName);
        // Connection con = DriverManager.getConnection(connctUrl, userName, password);
        Connection con = DriverManager.getConnection(connctUrl);
        Statement stmt = con.createStatement();
        String sql = "select * from student";
        PreparedStatement ps = con.prepareStatement(sql);

        ResultSet res = ps.executeQuery();
        int col = res.getMetaData().getColumnCount();
        System.out.println("=====================================");
        while (res.next()) {
            for (int i = 1; i <= col; i++) {
                System.out.print(res.getString(i) + "\t");
            }
            System.out.print("\n");
        }
        stmt.close();
        con.close();
    }

}
